<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>arduino array test</title>
<link rel="stylesheet" href="style.css" />
<script type="text/javascript">
var oldState = "null";
var c=0;
var t;
/*Set Loop Which looks for input*/
function timer()
{
getFile();
c=c+1;
t=setTimeout("timer()",50);
}


function getFile() {
      var url = "arduino_data.txt?timestamp=" + new Date().getTime();
      xmlhttp=new XMLHttpRequest();
      xmlhttp.open("GET", url, true);
      xmlhttp.onreadystatechange=postFileReady;
      xmlhttp.send(null);
}

function postFileReady() {
   if (xmlhttp.readyState==4) { 
     if (xmlhttp.status==200) { 
	   var inputArr = xmlhttp.responseText.split(',');
	   var switchStates = inputArr[1].split("'");
	   var analogValues = inputArr[3].split("'");
	   updateDisplay(switchStates,analogValues);
     }
   }
}

var divNamesArr = ['s0','s1','s2','s3','s4','s5'];
var stateColor = ['#FF0000','#00FF00'];

function updateDisplay(switchstates,analogvalues) {
	for (i=0;i<=switchstates.length;i=i+1) {
		document.getElementById(divNamesArr[i]).innerHTML=analogvalues[i];
		document.getElementById(divNamesArr[i]).style.background 
		= 'rgb('+analogvalues[i]/4+','+(1024-analogvalues[i])/4+',0)';
		//stateColor[switchstates[i]];
  	}
}

</script>
</head>
<body onLoad="timer();">
<h1> arduino array test </h1>
<div id="switches">
<ul>
	<li><div id="s0"></div></li>
	<li><div id="s1"></div></li>
	<li><div id="s2"></div></li>
	<li><div id="s3"></div></li>
	<li><div id="s4"></div></li>
	<li><div id="s5"></div></li>
</ul>
</div>

</body>
</html>
